<?php
namespace Common\Model;
use Think\Model;
/*
 * 手机品牌表
 */
class PhoneBrandModel extends Model{
    
     protected $_auto = array(/* array(完成字段1,完成规则,[完成条件,附加规则]) */
        array('addTime', 'time', 1, 'function'),
        array('updateTime', 'time', 2, 'function'),
        array('isOn', '1', 1),
    );  // 自动完成定义
	
     /*检查品牌存在*/
    public function checkBrandExist($brandID){
       return($this->where("brandID = $brandID")->find());
    }
     
     
     /*
      * 获取一条品牌信息
     */
	public function getPhoneBrand($id,$where=array(),$field = "*"){
     	$where['brandID']=$id;
     	$rt = $this->field($field)->where($where)->find();
     	return $rt;
    }

    /*
     * 获取品牌列表
    */
	public function getPhoneBrandList($pageNo = 1, $pageSize = 15, $where = array(), $order = array(), $field = "*") {
        $rt = $this->field($field)->where($where)->page("$pageNo,$pageSize")->order($order)->select();
        return $rt;
    }
	
    /*
     * 获取品牌列表总数
    */
    public function getPhoneListLength($where = array()) {
           $result = $this->where($where)->count();
           return $result;
    }
	      
    /*
      * 添加
      */
     public function addBrand($data=''){
         $rt = false;
        if ($this->create($data)) {
            $rt = $this->add();
        }
        return $rt;
     }
     
     /*
      * 更新
      */
      public function updateBrand($data = '') {
        $rt = false;
        if ($this->create($data)) {
            $rt = $this->save();
        }
        return $rt;
           
    }    
    
    /*
     * 编辑
     */
    public function editBrand($brandID){
        $brand = $this->where("brandID = $brandID")->find();  //，find()返回一个一维数组，select()返回一个二维数组
        return $brand;          //返回一维数组
    }
    
    
    /*
     * 移除，只是隐藏，并非真的从数据库中删除数据
     */
    public function deleteBrand($brandID){
        $data['isOn']=0;
        $data['brandID']=$brandID;
        $brand = $this->save($data);
        return $brand;          //成功返回一个真值
    }
}
?>